function h2=update_info(h2,count)
% function h2=update_info(h2,count)
% first call should be with no arg's in to create the fig
% it will return the handle for h2
% all remaings calls need that h2 and count
% count = a cell of strings
% ~bcoe

% max_trials=10
% trial=2
% state=3
% ii=1
% RT(trial-1,ii)=456
% RT(trial,ii)=132
% response(trial-1,ii)=1
% response(trial,ii)=2
% goal(trial-1,ii)=1
% goal(trial,ii)=2
% percor=89.5
% last5=99.5
% event_time=3546
% index=3
% state_end_time(index+1)=2000
% tgt_cnt=1
% count{1} = sprintf('  State: %s\n Trial#:%3d of%3d ',t_state{state},trial,max_trials);
% if trial>0
%     T_A='';T_B='';T_C='';
%     if state<S.OUTCOME && trial>2
%         count{2} = sprintf('(data for trial-1)\n');
%         for ii =1:tgt_cnt
%             T_A=[T_A sprintf('    RT%d:%3d',ii, RT(trial-1,ii))]; %#ok<AGROW>
%             T_B=[T_B sprintf('  resp%d:%3d',ii, response(trial-1,ii))];%#ok<AGROW>
%             T_C=[T_C sprintf('  goal%d:%3d',ii, goal(trial-1,ii))];%#ok<AGROW>
%         end
%     else
%         count{2} = sprintf('(data for trial)\n');
%         for ii =1:tgt_cnt
%             T_A=[T_A sprintf('    RT%d:%3d',ii, RT(trial,ii))];%#ok<AGROW>
%             T_B=[T_B sprintf('  resp%d:%2d ',ii, response(trial,ii))];%#ok<AGROW>
%             T_C=[T_C sprintf('  goal%d:%2d ',ii, goal(trial,ii))];%#ok<AGROW>
%         end
%     end
%     count{3} = sprintf('%s\n',T_A);
%     count{4} = sprintf('%s\n',T_B);
%     count{5} = sprintf('%s\n',T_C);
% end
% %fprintf('%s \n',['    TR: ' num2str(ceil(event_time/TR)) ]);
% count{6} = sprintf('Correct:%4.1f%% (last5=%4.1f%%)\n',percor,last5);
% count{7} = sprintf('  Trial: %3d of %3d\n',trial,max_trials);
% %count{8} = sprintf('   Time: %6.0f : %3d\n',event_time,state_end_time(index+1));
%
if nargin == 0
    h1=figure(543);clf
    set(h1,'DockControls','off','MenuBar','none','NumberTitle','off','ToolBar','none','HitTest','off','Color',[0 0 0],'visible','off');%,'visible','off'
    h2=uicontrol('Style','text','HorizontalAlignment','left','BackgroundColor',[0 0 0],'ForegroundColor',[ 1 1 1]);
    set(h2,'string','start','Units','normalized','pos',[0.05    0.05   0.9    0.9],'FontName','Monospaced','fontsize',12,'FontWeight','bold','tag','update_info_box')
    
    Monitorpixels=get(0,'MonitorPositions');
    window1=min(Monitorpixels);
    FigPos=window1+[.5 .5 -1 -1]*(max(window1)*.1);
    mainwindow=getWidth(com.mathworks.mde.desk.MLDesktop.getInstance.getMainFrame)/2 ...
        +getX(com.mathworks.mde.desk.MLDesktop.getInstance.getMainFrame.location);% added by bcoe
    if mainwindow+1>=Monitorpixels(1,1) && mainwindow<Monitorpixels(1,3)
        FigPos(1)=(Monitorpixels(1,1)+((Monitorpixels(1,3)-Monitorpixels(1,1))/2)-(FigPos(3)/2));% added by bcoe to  screen 1
        FigPos(2)=(Monitorpixels(1,4)-FigPos(4))/1.75;
    else
        FigPos(1)=(Monitorpixels(end,1)+((Monitorpixels(end,3)-Monitorpixels(end,1))/2)-(FigPos(3)/2));% added by bcoe to screen 2
        FigPos(2)=(Monitorpixels(end,4)-FigPos(4))/1.75;
    end
    FigPos=round(FigPos);
    set(h1,'OuterPosition',FigPos,'visible','on');
    drawnow;
    pause(.5)
else
    if h2 == -1
        close(get(findobj('tag','update_info_box'),'parent'));        
    else
        set(h2,'string',[count{:}]);
        drawnow('update')
    end
end
%
% tic
% for ii =1:10000
%     count{7} = sprintf('  Trial: %3d of %3d\n',ii,max_trials);
%     set(h2,'string',[count{:}])
%     %drawnow('expose')
%
% end
% toc


